package com.yr.ryjk.score;

import java.util.Map;

import org.apache.log4j.Logger;
import org.hibernate.validator.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yr.ryjk.common.ErrorType;
import com.yr.ryjk.interceptor.authority.For;
import com.yr.ryjk.interceptor.authority.UserType;
import com.yr.ryjk.score.service.IScoreService;
import com.yr.ryjk.util.JSONUtil;
/**
 * 评分
 * @author Rick
 *
 */
@For(user=UserType.APP_USER)
@Controller
@RequestMapping("/score")
public class ScoreController {
	private Logger logger=Logger.getLogger(this.getClass());
	@Autowired
	private IScoreService scoreService;
	
	/**
	 * APP用户提交评分接口
	 * @param consultId
	 * @param commentContent
	 * @param scoreNum
	 * @param token
	 * @return
	 */
	@RequestMapping(value="/add",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> addScore(@RequestParam("consultId") @NotBlank String consultId,
			@RequestParam("commentContent") @NotBlank String commentContent,
			@RequestParam(value="scoreNum",defaultValue="5") int scoreNum,
			String token){		
		try{
			 scoreService.addScore(consultId,commentContent,scoreNum,token);
			 return JSONUtil.getJSON(ErrorType.SUCCESS);		 
		} catch (Exception e) {
			 logger.error(e.getMessage(),e);
			 return JSONUtil.getJSON(ErrorType.SERVER_ERROR);
		}
	}

	/**
	 * 用户分批获取自己评价记录接口
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@RequestMapping(value="/user/getScores",method=RequestMethod.GET)
	@ResponseBody
	public Map<String, Object> listOf(@RequestParam(value="pageNo",defaultValue="1") int pageNo,
			@RequestParam(value="pageSize",defaultValue="10") int pageSize,
			@RequestParam("token") @NotBlank String token){
		try {
			return JSONUtil.getJSON(ErrorType.SUCCESS,scoreService.getListOfPage(pageNo,pageSize,token));
		} catch (Exception e) {
			logger.error(e.getMessage(),e);
			return JSONUtil.getJSON(ErrorType.SERVER_ERROR);
		}
	}
	
	/**
	 * 医生分批获取自己收到的评分记录列表接口
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@RequestMapping(value="/doctor/getScores",method=RequestMethod.GET)
	@ResponseBody
	public Map<String, Object> listOfScores(@RequestParam(value="pageNo",defaultValue="1") int pageNo,
			@RequestParam(value="pageSize",defaultValue="10") int pageSize,
			@RequestParam("token") @NotBlank String token){
		try {
			return JSONUtil.getJSON(ErrorType.SUCCESS,scoreService.getListOfScores(pageNo,pageSize,token));
		} catch (Exception e) {
			logger.error(e.getMessage(),e);
			return JSONUtil.getJSON(ErrorType.SERVER_ERROR);
		}
	}
}